package cn.bankAutoOffice.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 金健伟
 * @DATE 2023/3/17 8:57
 * 功能说明：
 */

@RestControllerAdvice
public class TestException {

    private static final Logger LOG = LoggerFactory.getLogger(TestException.class);

    // 捕获全局异常，处理所有不可知的异常
    @ExceptionHandler(value=Exception.class)
    Object handleException(Exception e, HttpServletRequest request){
        LOG.error("url{},msg{}", request.getRequestURL(),e.getMessage());
        Map<String, Object> map = new HashMap<>();
        map.put("code",400);
        map.put("msg","错误信息如下：" + e.getMessage());
        map.put("url","请求地址：" + request.getRequestURL());
        return map;
    }

}
